package leet.ku._205;

import java.util.HashMap;
import java.util.Map;

public class Solution {
	public boolean isIsomorphic(String s, String t) {
		return check(s, t) && check(t, s);
	}
	
	private boolean check(String s, String t) {
		Map<Character, Character> records = new HashMap<Character, Character>();
		for (int i = 0; i < s.length(); i++)
			if (records.containsKey(s.charAt(i)) && records.get(s.charAt(i)) != t.charAt(i))
				return false;
			else
				records.put(s.charAt(i), t.charAt(i));
		return true;
	}
	
//	public boolean isIsomorphic(String s1, String s2) {
//        int[] m = new int[512];
//        for (int i = 0; i < s1.length(); i++) {
//            if (m[s1.charAt(i)] != m[s2.charAt(i)+256]) return false;
//            m[s1.charAt(i)] = m[s2.charAt(i)+256] = i+1;
//        }
//        return true;
//    }
}